<include file="public@header"/>
<style type="text/css">  
input{  
    width:150px;  
    padding:1px;  
}  
#popup{  
    position:absolute;  
    width:500px;  
    color:#004a7e; 
    background-color:#C0C0C0;   
    /*left:120px;  */
    top:33px;  
}  
#spopup{  
    position:absolute;  
    width:500px;  
    color:#004a7e; 
    background-color:#C0C0C0;   
    /*left:120px;  */
    top:33px;  
}  
.show{  
    border:1px solid #909090;  
}  
ul{  
    list-style-type:none;  
    color:#004a7e;  
}  
._hover{  
    color:#ffffff;  
    background-color:#004a7e;  
}  
 ul{margin:0;padding:0}
</style>  
</head>
<body>
	<div class="wrap">
		<ul class="nav nav-tabs">

			<li><a href="{:url('Customer/index')}">客户</a></li>
			<li class="active"><a href="{:url('Customer/addCustomer')}">添加</a></li>
			<!-- 	<li class="active><a href="{:url('station/index')}">园区添加</a></li> -->
			<!-- <li ><a href="javascript:;">编辑分类</a></li> -->
		</ul>

		<form method="post" class="form-horizontal  margin-top-20" action="addCustomer">
			<input type="hidden" name="salesman" value="">	
			<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">公司名称<span class="form-required">*</span></label>
				<div class="col-md-6 col-sm-10">
					<input class="form-control" type="text" name="customer_name" value="" required="true">
				</div>
			</div>
		
			<!-- <div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">客户性质<span class="form-required">*</span></label>
				<div class="col-md-6 col-sm-10">
					<input class="form-control" type="text" name="customer_type" value="" required="true">
				</div>
			</div> -->
			<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">客户性质</label>
				<div class="col-md-6 col-sm-10">
					<select class="form-control" name="customer_type" id="parent_id">
						<option value="">==请选择==</option>

						<option value="1">项目客户</option>
						<option value="2">合作客户</option>


					</select>
				</div>
			</div>
			<div class="form-group"  style="display: none">
				<!-- <label for="input-name" class="col-sm-2 control-label">业务员<span class="form-required">*</span></label> -->
				<div class="col-md-6 col-sm-10">
					<input class="form-control" type="hidden" name="salesman" value="" required="true">
				</div>
			</div>
			
			<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">客户职位<span class="form-required"></span></label>
				<div class="col-md-6 col-sm-10">
					<input class="form-control" type="text" name="position" value="" >
				</div>
			</div>

			<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">来源<span class="form-required">*</span></label>
				<div class="col-md-6 col-sm-10">
					<!-- <input class="form-control" type="text" name="other_link" value="" > -->
					<select class="form-control" name="other_link" id="parent_id">
						<option value="">==请选择==</option>
						<volist name="link_way" id="vo">
			 				<option value="{$vo.id}">{$vo.name}</option>
			 			</volist>
					<!-- 	<option value="1">电话</option>
						<option value="2">来访</option>
						<option value="3">熟人介绍</option>
						<option value="4">其他</option>
					 -->

					</select>
				</div>
			</div>
			<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">客户电话<span class="form-required">*</span></label>
				<div class="col-md-6 col-sm-10">
					<input class="form-control" type="text" name="mobile" value="" required="true">
				</div>
			</div>

		
<!-- 			<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">领域<span class="form-required">*</span></label>
				<div class="col-md-6 col-sm-10">
					<input class="form-control" type="text" name="field" value="" >
				</div>
			</div>
 -->
			<div class="form-group">
			 	<label for="input-name" class="col-sm-2 control-label">领域</label>
			 	<div class="col-md-6 col-sm-10">
			 		<select class="form-control" name="field" id="parent_id">
			 			<option value="">==请选择==</option>
			 			<volist name="cate_list" id="vo">
			 				<option value="{$vo.id}">{$vo.name}</option>
			 			</volist>


			 		</select>
			 	</div>
			</div>
			
		<!-- 	<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">跟进情况<span class="form-required">*</span></label>
				<div class="col-md-6 col-sm-10">
					<input class="form-control" type="text" name="follow_state" value="" required="true">
				</div>
			</div> -->
			<div class="form-group">
			<label for="input-name" class="col-sm-2 control-label">融资阶段 <span class="form-required">*</span></label>
				<div class="col-md-6 col-sm-10">
					<select class="form-control" name="stage" id="parent_id" required="true">
						<option value="">==请选择==</option>
						<volist name="stages" id="vo">
						<option value="{$vo.id}">{$vo.name}</option>
						</volist>
						
					<!-- 	<option value="0">未跟进 </option>
						<option value="1"> 初步洽谈</option>
						<option value="2"> 需求确认</option>
						<option value="3"> 意向确认</option>
						<option value="4"> 入孵签订</option>
						<option value="5"> 客户流失</option> -->
					</select>
				</div>
			</div>
			<div class="form-group">
			<label for="input-name" class="col-sm-2 control-label">跟进阶段 <span class="form-required">*</span></label>
				<div class="col-md-6 col-sm-10">
					<select class="form-control" name="follow_stage" id="parent_id" required="true">
						<option value="">==请选择==</option>
						<volist name="gen_stage" id="vo">
						<option value="{$vo.id}">{$vo.name}</option>
						</volist>
						
					<!-- 	<option value="0">未跟进 </option>
						<option value="1"> 初步洽谈</option>
						<option value="2"> 需求确认</option>
						<option value="3"> 意向确认</option>
						<option value="4"> 入孵签订</option>
						<option value="5"> 客户流失</option> -->
					</select>
				</div>
			</div>
			<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">跟进情况<span class="form-required">*</span></label>
				<div class="col-md-6 col-sm-10">
					<!-- <input class="form-control" type="text" name="follow_state" value="" required="true"> -->
					  <textarea class="form-control" name="follow_state" style="height: 50px;"
                                      placeholder="请填跟进情况"></textarea>
				</div>
			</div>
		<!-- 	<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">对接人<span class="form-required">*</span></label>
				<div class="col-md-6 col-sm-10">
					<input class="form-control" type="text" name="linkman" value="" required="true">
				</div>
			</div> -->
			<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">业务员<span class="form-required"></span></label>
				<div class="col-md-6 col-sm-10">
					<!-- <input class="form-control" type="text" name="other_link" value="" > -->
				<!-- 	<select class="form-control" name="salesman" id="parent_id">
						<option value="">==选择业务员==</option>\
						<volist name="salesman" id="vo">
								<option value="{$vo.id}">{$vo.user_login}</option>
						</volist>
					</select> -->

				<input class="form-control" type="text" name="snames" id="snames" value="" onkeyup="sfindNames()"  autocomplete="off">
					<div  id="spopup" style="z-index:2;float:left">  
						<ul id="sul_name"></ul>  
						</div>
				</div>
			</div>
			<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">业务员电话<span class="form-required"></span></label>
				<div class="col-md-6 col-sm-10">
					<input class="form-control" type="text" name="salesmobile" value="" >
				</div>
			</div>
			

		</div>
			<!-- <div class="form-group">
				<label for="input-remark" class="col-sm-2 control-label">备注</label>
				<div class="col-md-6 col-sm-10">
					<label class="radio-inline js-icheck"><input type="radio" name="status" value="1" checked>显示</label>
					<label class="radio-inline js-icheck"><input type="radio" name="status" value="0" <if condition="1">checked</if>>隐藏</label>
				</div>
			</div> -->
			<div class="form-group">
				<div class="col-sm-offset-2 col-sm-10">
					<!-- <input type="hidden" name="id" value="1"> -->
					<button type="submit" class="btn btn-primary js-ajax-submit">{:lang('SAVE')}</button>
					<a class="btn btn-default" href="{:url('index',['type_id'=>1])}">{:lang('BACK')}</a>
				</div>
			</div>
		</form>
	</div>
	<script src="__STATIC__/js/admin.js"></script>
	<script type="text/javascript">
		$(function() {
			$("select[name=salesselect]").change(function(){
				name=$(this).find("option:selected").text();
				$("input[name=salesman]").val(name);
				//$("select[name=salesselect]").val("");

			})	
			　$("input[name=salesman]").mouseout(function(){
				name=$(this).val();
				$.post("{:url('Customer/check_sales')}",{name:name},function(data,status){
						if(data==0){
							// if(confirm("该业务员不存在是否需要添加？")){
							// 	$.post("{:url('Customer/check_sales')}",{name:name,sure:1},function(data,status){

							// 	})
							// }	
						}
				})
			});
		});





















	var soInput;  
	var soPopDiv;  
	var soNameUl;  
	
	function sinitVars(){  
		soInput = $("#snames");  
		soPopDiv = $("#spopup");  
		soNameUl = $("#sul_name");  
	}  
	function sclearNames(){  
		soNameUl.empty();  
		soPopDiv.removeClass("show");  
	}  
	function ssetNames(the_names){  
		sclearNames();  
		soPopDiv.addClass("show");  
		for(var i=0;i<the_names.length;i++)  
			soNameUl.append($("<li>"+the_names[i]+"</li>"));  
		soNameUl.find("li").click(function(){  
			soInput.val($(this).text());  
			sclearNames();  
		}).hover(  
		function(){  
			$(this).addClass("_hover");},  
			function(){  
				$(this).removeClass("_hover");}  
				);  
	}  
	$("#snames").change(function(){
		//alert(31231);
		sfindNamess()
	})
	
	function sfindNames(){  
		room_type=$("input[name=room_type]").val();
		room_id=$("input[name=room_id]").val();
		// alert(room_type);
		// alert(room_id);
		//alert(1231);
		sinitVars();  
		if(soInput.val().length >0){  
			$.post(  
				"{:url('Order/salesTip')}",{oData: soInput.val(),room_type:room_type,room_id:room_id} ,function(data){  
					var aResult = new Array(); 
				
					if(data.length>0){  
						aResult = data.split(",");  
						ssetNames(aResult);  
					}  
					else  
						sclearNames();  
				});  
		}  
		else  
			sclearNames();  
	}  
	function sfindNamess(){  
		room_type=$("input[name=room_type]").val();
		room_id=$("input[name=room_id]").val();
		//alert(1231);
		sinitVars();  
		if(soInput.val().length >0){  
			$.post(  
				"{:url('Order/salesTips')}",{oData: soInput.val(),room_type:room_type,room_id:room_id} ,function(data){  
					var aResult = new Array(); 
					if(data==''){
						if(role!=3){
							//alert(soInput.val());
							sales=soInput.val();
							//alert(sales);
							if(confirm("该业务员不存在，需要添加此业务员？")){
								location.href="{:url('User/adds')}?sales="+sales;
							}else{
								$("#snames").val('');	
							}
						}else{

						}
						//alert('该客户不存在，请先添加此客户');
						
					} 
					// if(data.length>0){  
					// 	aResult = data.split(",");  
					// 	ssetNames(aResult);  
					// }  
					// else  
					// 	sclearNames();  
				});  
		}  
		else  
			sclearNames();  
	}  
	role=<?php echo $role; ?>;
	namess="{$namess}";

	if(role==3){
		$('#snames').val(namess);
		$('#snames').attr('readonly','readonly');
		snames=$("#snames").val();
			//alert(snames);
			//$("input[name=customer_name]").val(customer_name);
			//alert(customer_name);
			// a='<?php echo $a='+customer_name+ '?>';
			// alert
			$.post("{:url('Order/getSalesId')}",{snames:snames},function(data,status){
				$("input[name=salesman]").val(data);



			})
		}
	$("#spopup").click(function(){

			snames=$("#snames").val();
			//alert(snames);
			//$("input[name=customer_name]").val(customer_name);
			//alert(customer_name);
			// a='<?php echo $a='+customer_name+ '?>';
			// alert
			 $.post("{:url('Order/getSalesId')}",{snames:snames},function(data,status){
                      $("input[name=salesman]").val(data);

			

			 })
			//$("input[name=customer_name]").val(customer_name);

		});
	</script>
</body>
</html>